# -*-coding: utf-8 -*-
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, Application
import os


class IndexHandler(RequestHandler):
    def get(self):
        self.write("hello,world")


class LoginHandler(RequestHandler):
    def get(self):
        self.render("login.html")

    def post(self):
        username = self.get_argument('username')
        password = self.get_argument('password')
        # self.write(f'username={username!r},password={password!r}')

        items = [
            'JavaScript',
            'Python',
            'Java',
            'Node.js',
            'C++'
        ]
        self.render('home.html', items=items)


def make_app():
    routes = [(r'/', IndexHandler),
              (r'/login', LoginHandler)]
    application = Application(routes,
                              debug=True,
                              template_path=os.path.join(os.path.dirname(__file__), 'templates'),
                              static_path=os.path.join(os.path.dirname(__file__), 'static'))
    return application


if __name__ == '__main__':
    app = make_app()
    app.listen(8888)
    print('Serving on Port 8888...')
    IOLoop.current().start()
